// 音符频率定义
#define NOTE_C4 261.63f
#define NOTE_D4 293.66f
#define NOTE_E4 329.63f
#define NOTE_F4 349.23f
#define NOTE_G4 392.00f
#define NOTE_A4 440.00f
#define NOTE_B4 493.88f
#define NOTE_C5 523.25f
#define NOTE_D5 587.33f
#define NOTE_E5 659.25f
#define NOTE_F5 698.46f
#define NOTE_G5 783.99f
#define REST 0.0f  // 休止符

// 音符时值定义（以四分音符为基准）
#define WHOLE_NOTE 1600    // 全音符
#define HALF_NOTE 800      // 二分音符
#define QUARTER_NOTE 400   // 四分音符
#define EIGHTH_NOTE 200    // 八分音符
#define SIXTEENTH_NOTE 100 // 十六分音符

// 音符结构体
typedef struct {
    float frequency;  // 频率(Hz)
    int duration;     // 时长(ms)
} Note;

// 小星星乐谱
const Note little_star_notes[] = {
    // 第一乐句
    {NOTE_C4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_A4, QUARTER_NOTE}, {NOTE_A4, QUARTER_NOTE},
    {NOTE_G4, HALF_NOTE},
    
    {NOTE_F4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_D4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_C4, HALF_NOTE},
    
    // 重复乐句...
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_D4, HALF_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_D4, HALF_NOTE},
    
    // 最后乐句（重复）
    {NOTE_C4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_A4, QUARTER_NOTE}, {NOTE_A4, QUARTER_NOTE},
    {NOTE_G4, HALF_NOTE},
    
    {NOTE_F4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_D4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_C4, HALF_NOTE}
};

// 生日快乐乐谱
const Note happy_birthday_notes[] = {
    // 第一段
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_A4, HALF_NOTE}, {NOTE_G4, HALF_NOTE},
    {NOTE_C5, HALF_NOTE}, {NOTE_B4, WHOLE_NOTE},
    
    // 第二段
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_A4, HALF_NOTE}, {NOTE_G4, HALF_NOTE},
    {NOTE_D5, HALF_NOTE}, {NOTE_C5, WHOLE_NOTE},
    
    // 第三段
    {NOTE_G4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_G5, HALF_NOTE}, {NOTE_E5, HALF_NOTE},
    {NOTE_C5, HALF_NOTE}, {NOTE_B4, QUARTER_NOTE},
    {NOTE_A4, QUARTER_NOTE},
    
    // 第四段
    {NOTE_F5, QUARTER_NOTE}, {NOTE_F5, QUARTER_NOTE},
    {NOTE_E5, HALF_NOTE}, {NOTE_C5, HALF_NOTE},
    {NOTE_D5, HALF_NOTE}, {NOTE_C5, WHOLE_NOTE}
};

// 两只老虎乐谱
const Note two_tigers_notes[] = {
    // 第一段
    {NOTE_C4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_G4, HALF_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_G4, HALF_NOTE},
    
    // 第二段
    {NOTE_G4, QUARTER_NOTE}, {NOTE_A4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_C4, HALF_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_A4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_C4, HALF_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_C4, HALF_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_C4, HALF_NOTE},
    
    {REST, HALF_NOTE}  // 结束休止符
};

// 圣诞快乐(Jingle Bells)
const Note jingle_bells_notes[] = {
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_E4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_E4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_C4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_E4, HALF_NOTE}, {REST, QUARTER_NOTE},
    {REST, QUARTER_NOTE}, {REST, QUARTER_NOTE},
    
    {NOTE_F4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    
    {NOTE_F4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_D4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_D4, HALF_NOTE}, {REST, QUARTER_NOTE},
    {NOTE_G4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    // 重复第一段...
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_E4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_E4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_C4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_E4, HALF_NOTE}, {REST, QUARTER_NOTE},
    {REST, QUARTER_NOTE}, {REST, QUARTER_NOTE}
};

// 铃儿响叮当(Ding Dong Bell)
const Note ding_dong_bell_notes[] = {
    {NOTE_C4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_C5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_C5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_D4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_A4, QUARTER_NOTE}, {NOTE_D5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_D4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_A4, QUARTER_NOTE}, {NOTE_D5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_B4, QUARTER_NOTE}, {NOTE_E5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_E4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    {NOTE_B4, QUARTER_NOTE}, {NOTE_E5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_C5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_G4, QUARTER_NOTE}, {NOTE_C5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_B4, QUARTER_NOTE},
    {NOTE_D5, QUARTER_NOTE}, {NOTE_G5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_B4, QUARTER_NOTE},
    {NOTE_D5, QUARTER_NOTE}, {NOTE_G5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_F4, QUARTER_NOTE}, {NOTE_A4, QUARTER_NOTE},
    {NOTE_C5, QUARTER_NOTE}, {NOTE_F5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE},
    
    {NOTE_F4, QUARTER_NOTE}, {NOTE_A4, QUARTER_NOTE},
    {NOTE_C5, QUARTER_NOTE}, {NOTE_F5, QUARTER_NOTE},
    {REST, EIGHTH_NOTE}
};

// 欢乐颂(Ode to Joy)
const Note ode_to_joy_notes[] = {
    // 第一段
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_D4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    
    {NOTE_E4, HALF_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_D4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    // 第二段
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_D4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    
    {NOTE_D4, HALF_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_C4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    // 第三段
    {NOTE_D4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    
    {NOTE_D4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_E4, EIGHTH_NOTE},
    {NOTE_C4, EIGHTH_NOTE},
    
    {NOTE_D4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_E4, EIGHTH_NOTE},
    {NOTE_D4, EIGHTH_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    {NOTE_G4, HALF_NOTE}, {REST, QUARTER_NOTE},
    
    // 第四段（重复第一段）
    {NOTE_E4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    {NOTE_F4, QUARTER_NOTE}, {NOTE_G4, QUARTER_NOTE},
    
    {NOTE_G4, QUARTER_NOTE}, {NOTE_F4, QUARTER_NOTE},
    {NOTE_E4, QUARTER_NOTE}, {NOTE_D4, QUARTER_NOTE},
    
    {NOTE_C4, QUARTER_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_D4, QUARTER_NOTE}, {NOTE_E4, QUARTER_NOTE},
    
    {NOTE_D4, HALF_NOTE}, {NOTE_C4, QUARTER_NOTE},
    {NOTE_C4, HALF_NOTE}, {REST, QUARTER_NOTE}
};

// 歌曲结构体
typedef struct {
    const char* name;
    const Note* notes;
    int noteCount;
} Song;

// 歌曲列表
const Song songs[] = {
    {"小星星", little_star_notes, sizeof(little_star_notes)/sizeof(Note)},
    {"生日快乐", happy_birthday_notes, sizeof(happy_birthday_notes)/sizeof(Note)},
    {"两只老虎", two_tigers_notes, sizeof(two_tigers_notes)/sizeof(Note)},
    {"圣诞快乐", jingle_bells_notes, sizeof(jingle_bells_notes)/sizeof(Note)},
    {"铃儿响叮当", ding_dong_bell_notes, sizeof(ding_dong_bell_notes)/sizeof(Note)},
    {"欢乐颂", ode_to_joy_notes, sizeof(ode_to_joy_notes)/sizeof(Note)}
};

#define NUM_SONGS (sizeof(songs)/sizeof(Song))